$(function () {
    //获取url
    var url = localStorage.getItem("ajaxUrl");
    var machine = localStorage.getItem("ropewireMachine");
    var work_id = "";
    var work = "";
    var controlvalue_D = 2.800; //T
    var controlvalue_E = 0.500; //T
    var pass = 1;
    var focus = true;
    var qualityJson = {
        zj: "",
        bmzl: ""
    };

    $(".head .icon-lishi1").on("click", function () {
        var machine = $("section span.machine").html();
        if (machine != "空") {
            localStorage.setItem("ropewireMachine", machine);
        }
        window.location.href = "ropewire_lishi.html";
    });

    //搜索框 获取焦点
    $("#goods_id").focus();
    $("#goods_id").blur(function () {
        if (focus) {
            $("#goods_id").focus();
        }
    });

    $("div.page").on("click", "span.personal", function () {
        localStorage.removeItem("ropewireMachine");
        focus = false;
        $("#goods_id").blur();
    });

    $(".panel-overlay").on("click", function () {
        focus = true;
        setTimeout(function () {
            $("#goods_id").val("").focus();
        }, 1000);
    });

    //根据 id 得到 工单信息、机台信息
    getMachineFun(machine);

    function getMachineFun(machine) {
        if (machine) {
            $.ajax({
                headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                type: "post",
                url: url + '/app/ropewire/getRopewirePlanAndMaterialByMachine',
                data: {
                    machine: machine
                },
                dataType: 'json',
                json: 'callback',
                success: function (res) {
                    loading_hide();
                    if (res.success) {
                        var data = res.result;
                        if (data.ropewire && data.ropewire != "" && data.ropewire.status == "未接班") {
                            $.confirm("换班米长" + data.ropewire.length + "，是否确认？", function () {
                                $.ajax({
                                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                    type: "post",
                                    url: url + '/app/ropewire/confirmChangeTeam',
                                    data: {
                                        machine: machine
                                    },
                                    dataType: 'json',
                                    json: 'callback',
                                    success: function (result) {
                                        if (result.success) {
                                            work = data.plan;
                                            if (res.controlvalue) {
                                                if (res.controlvalue["D"]) {
                                                    controlvalue_D = res.controlvalue["D"];
                                                }
                                                if (res.controlvalue["E"]) {
                                                    controlvalue_E = res.controlvalue["E"];
                                                }
                                            }
                                            //填充 当前机台与当前用料
                                            $("section span.machine").html(machine);
                                            if (data.plan && data.plan.workplanNumber) {
                                                work_id = data.plan._id;
                                                $("section span.workplanNumber").html(data.plan.workplanNumber);
                                                $("section span.kh").html(data.plan.customerNameShort);
                                                $("section span.ropeGg").html(data.plan.ropeSpecification);
                                                $("section span.work_gg").html(data.plan.inventorySpecification);
                                                $("section span.work_zls").html(data.plan.detail.specifyWheelCount || "0");
                                                $("section span.work_completeWheelQuantity").html(data.plan.detail.completeWheelCount || "0");
                                                $("section span.work_weight").html(data.plan.detail.planQuantity);
                                                $("section span.work_completeWeight").html(data.plan.detail.completeQuantity ? Number(parseFloat(data.plan.detail.completeQuantity).toFixed(3)) : "0");
                                                $("section span.takeupWayWheel").html(data.plan.takeupWayWheel ? data.plan.takeupWayWheel : "");
                                                $("section span.planAxleLength").html(data.plan.planAxleLength ? data.plan.planAxleLength : "");
                                                $("section .inventoryMaterialsHtml").html(data.plan.inventoryMaterialsHtml ? data.plan.inventoryMaterialsHtml : "");
                                            } else {
                                                $("section span.workplanNumber").html("空");
                                                $("section span.kh").html("空");
                                                $("section span.ropeGg").html("空");
                                                $("section span.work_gg").html("空");
                                                $("section span.work_zls").html("空");
                                                $("section span.work_completeWheelQuantity").html("空");
                                                $("section span.work_weight").html("空");
                                                $("section span.work_completeWeight").html("空");
                                                $("section span.takeupWayWheel").html("空");
                                                $("section span.planAxleLength").html("空");
                                                $("section .inventoryMaterialsHtml").html("");
                                            }
                                            if (data.material && data.material.length > 0) {
                                                $("section div.material span.number").html(data.material[0].batch);
                                                $("section div.material span.gggh").html(data.material[0].inventorySteel + " " + data.material[0].inventoryDiameter + " " + data.material[0].wirerodmanufacturerCode);
                                                $("section div.material span.lh").html(data.material[0].stove);
                                                $("section div.material span.column").html(data.material[0].column);
                                                $("section div.material span.quantity").html(data.material[0].quantity);
                                                setAllmaterial(data.material);
                                                // if (Number(data.material[0].quantity) < 50) {
                                                //     $alert("当前原料剩余重量小于50KG了，请检查", 3000);
                                                // }
                                            } else {
                                                $("section div.material span.number").html("空");
                                                $("section div.material span.gggh").html("空");
                                                $("section div.material span.lh").html("空");
                                                $("section div.material span.column").html("空");
                                                $("section div.material span.quantity").html("空");
                                                setAllmaterial([]);
                                            }
                                            if (data.ropewire) {
                                                $(".bnt .shouxiao_tou").addClass("disabled").prop("disabled", true);
                                                $(".bnt .shouxiao_wei").removeClass("disabled").prop("disabled", false);
                                            } else {
                                                $(".bnt .shouxiao_tou").removeClass("disabled").prop("disabled", false);
                                                // $(".bnt .shouxiao_wei").addClass("disabled").prop("disabled", true);
                                                $(".bnt .shouxiao_wei").removeClass("disabled").prop("disabled", false);
                                            }
                                            //如果有吊秤
                                            /*if (data.machine.scales) {
                                                var html = '<option value="">请选择吊秤</option>';
                                                for (var j = 0; j < data.machine.scales.length; j++) {
                                                    html += '<option value="' + data.machine.scales[j].scaleNumber + '">' + data.machine.scales[j].scaleName + '</option>';
                                                }
                                                $("select#goods_cheng").html(html).val(data.material.scaleNumber || "").trigger("change");
                                            }*/
                                        } else {
                                            console.log(res);
                                            $alert(res.message);
                                        }
                                    },
                                    error: function (error) {
                                        console.log(error);
                                        $alert(error.responseText);
                                    }
                                });
                            })
                        } else {
                            //$alert(val + "扫描成功");
                            //填充 当前机台与当前用料
                            work = data.plan;
                            if (res.controlvalue) {
                                if (res.controlvalue["D"]) {
                                    controlvalue_D = res.controlvalue["D"];
                                }
                                if (res.controlvalue["E"]) {
                                    controlvalue_E = res.controlvalue["E"];
                                }
                            }
                            $("section span.machine").html(data.machine.machine);
                            if (data.plan && data.plan.workplanNumber) {
                                work_id = data.plan._id;
                                $("section span.workplanNumber").html(data.plan.workplanNumber);
                                $("section span.kh").html(data.plan.customerNameShort);
                                $("section span.ropeGg").html(data.plan.ropeSpecification);
                                $("section span.work_gg").html(data.plan.inventorySpecification);
                                $("section span.work_zls").html(data.plan.detail.specifyWheelCount || "0");
                                $("section span.work_completeWheelQuantity").html(data.plan.detail.completeWheelCount || "0");
                                $("section span.work_weight").html(data.plan.detail.planQuantity);
                                $("section span.work_completeWeight").html(data.plan.detail.completeQuantity ? Number(parseFloat(data.plan.detail.completeQuantity).toFixed(3)) : "0");
                                $("section span.takeupWayWheel").html(data.plan.takeupWayWheel ? data.plan.takeupWayWheel : "");
                                $("section span.planAxleLength").html(data.plan.planAxleLength ? data.plan.planAxleLength : "");
                                $("section .inventoryMaterialsHtml").html(data.plan.inventoryMaterialsHtml ? data.plan.inventoryMaterialsHtml : "");
                            } else {
                                $("section span.workplanNumber").html("空");
                                $("section span.kh").html("空");
                                $("section span.ropeGg").html("空");
                                $("section span.work_gg").html("空");
                                $("section span.work_zls").html("空");
                                $("section span.work_completeWheelQuantity").html("空");
                                $("section span.work_weight").html("空");
                                $("section span.work_completeWeight").html("空");
                                $("section span.takeupWayWheel").html("空");
                                $("section span.planAxleLength").html("空");
                                $("section .inventoryMaterialsHtml").html("");
                            }
                            if (data.material && data.material.length > 0) {
                                $("section div.material span.number").html(data.material[0].batch);
                                $("section div.material span.gggh").html(data.material[0].inventorySteel + " " + data.material[0].inventoryDiameter + " " + data.material[0].wirerodmanufacturerCode);
                                $("section div.material span.lh").html(data.material[0].stove);
                                $("section div.material span.column").html(data.material[0].column);
                                $("section div.material span.quantity").html(data.material[0].quantity);
                                setAllmaterial(data.material);
                                // if (Number(data.material[0].quantity) < 50) {
                                //     $alert("当前原料剩余重量小于50KG了，请检查", 3000);
                                // }
                            } else {
                                $("section div.material span.number").html("空");
                                $("section div.material span.gggh").html("空");
                                $("section div.material span.lh").html("空");
                                $("section div.material span.column").html("空");
                                $("section div.material span.quantity").html("空");
                                setAllmaterial([]);
                            }
                            if (data.ropewire) {
                                $(".bnt .shouxiao_tou").addClass("disabled").prop("disabled", true);
                                $(".bnt .shouxiao_wei").removeClass("disabled").prop("disabled", false);
                            } else {
                                $(".bnt .shouxiao_tou").removeClass("disabled").prop("disabled", false);
                                // $(".bnt .shouxiao_wei").addClass("disabled").prop("disabled", true);
                                $(".bnt .shouxiao_wei").removeClass("disabled").prop("disabled", false);
                            }
                            //如果有吊秤
                            /*if (data.machine.scales) {
                                var html = '<option value="">请选择吊秤</option>';
                                for (var j = 0; j < data.machine.scales.length; j++) {
                                    html += '<option value="' + data.machine.scales[j].scaleNumber + '">' + data.machine.scales[j].scaleName + '</option>';
                                }
                                $("select#goods_cheng").html(html).val(data.material.scaleNumber || "").trigger("change");
                            }*/
                        }
                    } else {
                        console.log(res)
                        $alert(res.message);
                    }
                },
                error: function (error) {
                    loading_hide();
                    console.log(error);
                    $alert(error.responseText);
                }
            });
        } else {
            $("section span.machine").html("空");
        }
    }

    $("#goods_id").on("keydown", function (event) {
        if (event.keyCode == "13") {
            if (pass == 0) {
                return
            }
            pass = 0;
            var val = $(this).val();
            $("#goods_id").val("");
            if (!val) {
                $alert("请扫描干湿拉机台！");
                pass = 1;
                setTimeout(function () {
                    $("#goods_id").val("").focus();
                }, 1400);
                return;
            } else {
                $.ajax({
                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                    type: "post",
                    url: url + '/app/ropewire/getRopewirePlanAndMaterialByMachine',
                    data: {
                        machine: val
                    },
                    dataType: 'json',
                    json: 'callback',
                    success: function (res) {
                        pass = 1;
                        loading_hide();
                        if (res.success) {
                            var data = res.result;
                            if (data.ropewire && data.ropewire != "" && data.ropewire.status == "未接班") {
                                $.confirm("换班米长" + data.ropewire.length + "，是否确认？", function () {
                                    $.ajax({
                                        headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                        type: "post",
                                        url: url + '/app/ropewire/confirmChangeTeam',
                                        data: {
                                            machine: val
                                        },
                                        dataType: 'json',
                                        json: 'callback',
                                        success: function (result) {
                                            if (result.success) {
                                                work = data.plan;
                                                if (res.controlvalue) {
                                                    if (res.controlvalue["D"]) {
                                                        controlvalue_D = res.controlvalue["D"];
                                                    }
                                                    if (res.controlvalue["E"]) {
                                                        controlvalue_E = res.controlvalue["E"];
                                                    }
                                                }
                                                //填充 当前机台与当前用料
                                                $("section span.machine").html(val);
                                                if (data.plan && data.plan.workplanNumber) {
                                                    work_id = data.plan._id;
                                                    $("section span.workplanNumber").html(data.plan.workplanNumber);
                                                    $("section span.kh").html(data.plan.customerNameShort);
                                                    $("section span.ropeGg").html(data.plan.ropeSpecification);
                                                    $("section span.work_gg").html(data.plan.inventorySpecification);
                                                    $("section span.work_zls").html(data.plan.detail.specifyWheelCount || "0");
                                                    $("section span.work_completeWheelQuantity").html(data.plan.detail.completeWheelCount || "0");
                                                    $("section span.work_weight").html(data.plan.detail.planQuantity);
                                                    $("section span.work_completeWeight").html(data.plan.detail.completeQuantity ? Number(parseFloat(data.plan.detail.completeQuantity).toFixed(3)) : "0");
                                                    $("section span.takeupWayWheel").html(data.plan.takeupWayWheel ? data.plan.takeupWayWheel : "");
                                                    $("section span.planAxleLength").html(data.plan.planAxleLength ? data.plan.planAxleLength : "");
                                                    $("section .inventoryMaterialsHtml").html(data.plan.inventoryMaterialsHtml ? data.plan.inventoryMaterialsHtml : "");
                                                } else {
                                                    $("section span.workplanNumber").html("空");
                                                    $("section span.kh").html("空");
                                                    $("section span.ropeGg").html("空");
                                                    $("section span.work_gg").html("空");
                                                    $("section span.work_zls").html("空");
                                                    $("section span.work_completeWheelQuantity").html("空");
                                                    $("section span.work_weight").html("空");
                                                    $("section span.work_completeWeight").html("空");
                                                    $("section span.takeupWayWheel").html("空");
                                                    $("section span.planAxleLength").html("空");
                                                    $("section .inventoryMaterialsHtml").html("");
                                                }
                                                if (data.material && data.material.length > 0) {
                                                    $("section div.material span.number").html(data.material[0].batch);
                                                    $("section div.material span.gggh").html(data.material[0].inventorySteel + " " + data.material[0].inventoryDiameter + " " + data.material[0].wirerodmanufacturerCode);
                                                    $("section div.material span.lh").html(data.material[0].stove);
                                                    $("section div.material span.column").html(data.material[0].column);
                                                    $("section div.material span.quantity").html(data.material[0].quantity);
                                                    setAllmaterial(data.material);
                                                    // if (Number(data.material[0].quantity) < 50) {
                                                    //     $alert("当前原料剩余重量小于50KG了，请检查", 3000);
                                                    // }
                                                } else {
                                                    $("section div.material span.number").html("空");
                                                    $("section div.material span.gggh").html("空");
                                                    $("section div.material span.lh").html("空");
                                                    $("section div.material span.column").html("空");
                                                    $("section div.material span.quantity").html("空");
                                                    setAllmaterial([]);
                                                }
                                                if (data.ropewire) {
                                                    $(".bnt .shouxiao_tou").addClass("disabled").prop("disabled", true);
                                                    $(".bnt .shouxiao_wei").removeClass("disabled").prop("disabled", false);
                                                } else {
                                                    $(".bnt .shouxiao_tou").removeClass("disabled").prop("disabled", false);
                                                    // $(".bnt .shouxiao_wei").addClass("disabled").prop("disabled", true);
                                                    $(".bnt .shouxiao_wei").removeClass("disabled").prop("disabled", false);
                                                }
                                                //如果有吊秤
                                                /*if (data.machine.scales) {
                                                    var html = '<option value="">请选择吊秤</option>';
                                                    for (var j = 0; j < data.machine.scales.length; j++) {
                                                        html += '<option value="' + data.machine.scales[j].scaleNumber + '">' + data.machine.scales[j].scaleName + '</option>';
                                                    }
                                                    $("select#goods_cheng").html(html).val(data.material.scaleNumber || "").trigger("change");
                                                }*/
                                            } else {
                                                console.log(res);
                                                $alert(res.message);
                                            }
                                        },
                                        error: function (error) {
                                            console.log(error);
                                            $alert(error.responseText);
                                        }
                                    });
                                })
                            } else {
                                $alert(val + "扫描成功");
                                //填充 当前机台与当前用料
                                work = data.plan;
                                if (res.controlvalue) {
                                    if (res.controlvalue["D"]) {
                                        controlvalue_D = res.controlvalue["D"];
                                    }
                                    if (res.controlvalue["E"]) {
                                        controlvalue_E = res.controlvalue["E"];
                                    }
                                }
                                $("section span.machine").html(data.machine.machine);
                                if (data.plan && data.plan.workplanNumber) {
                                    work_id = data.plan._id;
                                    $("section span.workplanNumber").html(data.plan.workplanNumber);
                                    $("section span.kh").html(data.plan.customerNameShort);
                                    $("section span.ropeGg").html(data.plan.ropeSpecification);
                                    $("section span.work_gg").html(data.plan.inventorySpecification);
                                    $("section span.work_zls").html(data.plan.detail.specifyWheelCount || "0");
                                    $("section span.work_completeWheelQuantity").html(data.plan.detail.completeWheelCount || "0");
                                    $("section span.work_weight").html(data.plan.detail.planQuantity);
                                    $("section span.work_completeWeight").html(data.plan.detail.completeQuantity ? Number(parseFloat(data.plan.detail.completeQuantity).toFixed(3)) : "0");
                                    $("section span.takeupWayWheel").html(data.plan.takeupWayWheel ? data.plan.takeupWayWheel : "");
                                    $("section span.planAxleLength").html(data.plan.planAxleLength ? data.plan.planAxleLength : "");
                                    $("section .inventoryMaterialsHtml").html(data.plan.inventoryMaterialsHtml ? data.plan.inventoryMaterialsHtml : "");
                                } else {
                                    $("section span.workplanNumber").html("空");
                                    $("section span.kh").html("空");
                                    $("section span.ropeGg").html("空");
                                    $("section span.work_gg").html("空");
                                    $("section span.work_zls").html("空");
                                    $("section span.work_completeWheelQuantity").html("空");
                                    $("section span.work_weight").html("空");
                                    $("section span.work_completeWeight").html("空");
                                    $("section span.takeupWayWheel").html("空");
                                    $("section span.planAxleLength").html("空");
                                    $("section .inventoryMaterialsHtml").html("");
                                }
                                if (data.material && data.material.length > 0) {
                                    $("section div.material span.number").html(data.material[0].batch);
                                    $("section div.material span.gggh").html(data.material[0].inventorySteel + " " + data.material[0].inventoryDiameter + " " + data.material[0].wirerodmanufacturerCode);
                                    $("section div.material span.lh").html(data.material[0].stove);
                                    $("section div.material span.column").html(data.material[0].column);
                                    $("section div.material span.quantity").html(data.material[0].quantity);
                                    setAllmaterial(data.material);
                                    // if (Number(data.material[0].quantity) < 50) {
                                    //     $alert("当前原料剩余重量小于50KG了，请检查", 3000);
                                    // }
                                } else {
                                    $("section div.material span.number").html("空");
                                    $("section div.material span.gggh").html("空");
                                    $("section div.material span.lh").html("空");
                                    $("section div.material span.column").html("空");
                                    $("section div.material span.quantity").html("空");
                                    setAllmaterial([]);
                                }
                                if (data.ropewire) {
                                    $(".bnt .shouxiao_tou").addClass("disabled").prop("disabled", true);
                                    $(".bnt .shouxiao_wei").removeClass("disabled").prop("disabled", false);
                                } else {
                                    $(".bnt .shouxiao_tou").removeClass("disabled").prop("disabled", false);
                                    // $(".bnt .shouxiao_wei").addClass("disabled").prop("disabled", true);
                                    $(".bnt .shouxiao_wei").removeClass("disabled").prop("disabled", false);
                                }
                                //如果有吊秤
                                /*if (data.machine.scales) {
                                    var html = '<option value="">请选择吊秤</option>';
                                    for (var j = 0; j < data.machine.scales.length; j++) {
                                        html += '<option value="' + data.machine.scales[j].scaleNumber + '">' + data.machine.scales[j].scaleName + '</option>';
                                    }
                                    $("select#goods_cheng").html(html).val(data.material.scaleNumber || "").trigger("change");
                                }*/
                            }
                        } else {
                            console.log(res);
                            $alert(res.message);
                        }
                    },
                    error: function (error) {
                        pass = 1;
                        loading_hide();
                        console.log(error);
                        $alert(error.responseText);
                    }
                });
            }
        }
    });

    function setAllmaterial(material) {
        console.log(material.length)
        var allMaterialHtml = "";
        for (var i = 1; i < material.length; i++) {
            allMaterialHtml += '  <div class="card-content-inner">' +
                '<p><span>编号 ：</span><span class="number">' + material[i].batch + '</span></p>' +
                '<p><span>规格钢号 ：</span><span class="gggh">' + material[i].inventorySteel + " " + material[i].inventoryDiameter +  + " " + material[i].wirerodmanufacturerCode + '</span></p>' +
                '<p><span>炉号 ：</span><span class="lh">' + material[i].stove + '</span>&nbsp;&nbsp;<span>卷号 ：</span><span class="column">' + material[i].column + '</span></p>' +
                '<p><span>剩余重量 ：</span><span class="quantity">' + material[i].quantity + '</span>T</p></div>'
        }
        $(".allMaterial").empty().html(allMaterialHtml).hide();
    }

    // 点击 下箭头
    $(".material").on("click", ".aaa", function (event) {
        var classname = $(this).attr("class");
        if (classname.indexOf("icon-xiashuangjiantou") > -1) {
            $(".allMaterial").show();
            $(this).removeClass("icon-xiashuangjiantou");
            $(this).addClass("icon-shangshuangjiantou");

        } else{
            $(".allMaterial").hide();
            $(this).removeClass("icon-shangshuangjiantou");
            $(this).addClass("icon-xiashuangjiantou");
        }
    });

    //点击 上料
    $(".bnt .shangliao").on("click", function () {
        var machine = $("section span.machine").html();
        var workplanNumber = $("section span.workplanNumber").html();
        if (!workplanNumber || workplanNumber == "空") {
            return $alert("请先扫描机台号");
        }
        if (!machine || machine == "空") {
            $alert("请先扫描干湿拉机台");
        } else {
            loading_show("获取中...");
            $.ajax({
                headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                type: "post",
                url: url + '/app/ropewire/isFeedMachine',
                dataType: 'json',
                data: {
                    id: work_id,
                    machine: $("section span.machine").html()
                },
                json: 'callback',
                cache: false,
                timeout: 60000,
                success: function (res) {
                    if (res.success) {
                        var data = res.result;
                        loading_hide();
                        var quantity = $("section .material span.quantity").html();
                        var addMaterial = $("section .addMaterial .card-content").length;
                        //if (quantity != "空" && Number(quantity) > 300) return $alert("剩余重量过大，请核对");
                        //if (addMaterial && addMaterial > 0) return $alert("存在累加用料，不可上料");
                        localStorage.setItem("work_id", work_id);
                        localStorage.setItem("ropewireMachine", machine);
                        window.location.href = "ropewire_sl.html";
                    } else {
                        console.log(res);
                        $alert(res.message);
                    }
                },
                error: function (error) {
                    //隐藏提示符 显示
                    loading_hide();

                    if (error.status == 0) {
                        $alert("请求超时，请再试一次！");
                    } else {
                        console.log(error);
                        $alert(error.responseText);
                    }
                }
            });
        }
    });

    // 点击 清楚 原料
    $(".bnt .clear").on("click", function () {
        var machine = $("section span.machine").html();
        var workplanNumber = $("section span.workplanNumber").html();
        var quantity = $("section div.material span.quantity").html();
        var number = $("section div.material span.number").html();
        if (!workplanNumber || workplanNumber == "空") {
            return $alert("请先扫描机台号");
        }
        if (!machine || machine == "空") {
            $alert("请先扫描干湿拉机台");
        } else {
            $.confirm("当前用料剩余" + quantity + "，确认清除吗？", function () {
                loading_show("清除中...");
                $.ajax({
                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                    type: "post",
                    url: url + '/app/ropewire/clearMachinematerial',
                    dataType: 'json',
                    data: {
                        id: work_id,
                        batch: number,
                        machine: machine
                    },
                    json: 'callback',
                    cache: false,
                    timeout: 60000,
                    success: function (res) {
                        if (res.success) {
                            var data = res.result;
                            loading_hide();
                            $alert("清除成功");
                            localStorage.setItem("ropewireMachine", machine);
                            setTimeout(function () {
                                window.location.href = "ropewire.html";
                            }, 1200);
                        } else {
                            console.log(res);
                            $alert(res.message);
                        }
                    },
                    error: function (error) {
                        //隐藏提示符 显示
                        loading_hide();

                        if (error.status == 0) {
                            $alert("请求超时，请再试一次！");
                        } else {
                            console.log(error);
                            $alert(error.responseText);
                        }
                    }
                });
            })
        }
    });

    //点击 头收线
    $(".bnt .shouxiao_tou").click(function () {
        var workplanNumber = $("section span.workplanNumber").html();
        if (!workplanNumber || workplanNumber == "空") {
            return $alert("请先扫描机台号");
        }
        if ($("div.material span.number").html() && $("div.material span.number").html() != "空") {
            $.modal({
                title: '头收线，是否打印标签？',
                buttons: [
                    {
                        text: '否',
                        onClick: function () {
                            if (pass == 0) {
                                return
                            }
                            pass = 0;
                            loading_show("头收线中...");
                            $.ajax({
                                headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                type: "post",
                                url: url + '/app/ropewire/ropewireTakeup_start',
                                dataType: 'json',
                                data: {
                                    id: work_id,
                                    machine: $("section span.machine").html(),
                                    print: false
                                },
                                json: 'callback',
                                cache: false,
                                timeout: 60000,
                                success: function (res) {
                                    pass = 1;
                                    if (res.success) {
                                        var data = res.result;
                                        loading_hide();
                                        $alert("头收线成功！");
                                        localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                        setTimeout(function () {
                                            window.location.href = "ropewire.html";
                                        }, 1200);
                                        // takeupPrint("ropeWire", res.result);
                                    } else {
                                        console.log(res);
                                        $alert(res.message);
                                    }
                                },
                                error: function (error) {
                                    pass = 1;
                                    //隐藏提示符 显示
                                    loading_hide();

                                    if (error.status == 0) {
                                        $alert("请求超时，请再试一次！");
                                    } else {
                                        console.log(error);
                                        $alert(error.responseText);
                                    }
                                }
                            });
                        }
                    }, {
                        text: '是',
                        onClick: function () {
                            if (pass == 0) {
                                return
                            }
                            pass = 0;
                            loading_show("头收线中...");
                            $.ajax({
                                headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                type: "post",
                                url: url + '/app/ropewire/ropewireTakeup_start',
                                dataType: 'json',
                                data: {
                                    id: work_id,
                                    machine: $("section span.machine").html(),
                                    print: true
                                },
                                json: 'callback',
                                cache: false,
                                timeout: 60000,
                                success: function (res) {
                                    pass = 1;
                                    if (res.success) {
                                        var data = res.result;
                                        loading_hide();
                                        $alert("头收线成功！");
                                        localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                        setTimeout(function () {
                                            window.location.href = "ropewire.html";
                                        }, 1200);
                                        takeupPrint("ropeWire", res.result);
                                    } else {
                                        console.log(res);
                                        $alert(res.message);
                                    }
                                },
                                error: function (error) {
                                    pass = 1;
                                    //隐藏提示符 显示
                                    loading_hide();

                                    if (error.status == 0) {
                                        $alert("请求超时，请再试一次！");
                                    } else {
                                        console.log(error);
                                        $alert(error.responseText);
                                    }
                                }
                            });
                        }
                    }
                ]
            });
            // $.confirm("确认头收线吗？", function () {
            //
            // }, function () {
            //     $("#goods_id").focus();
            //     focus = true;
            // })
        } else {
            $alert("请先上料！");
        }
    });
    //点击 收线
    $(".bnt .shouxiao_wei").click(function () {
        var workplanNumber = $("section span.workplanNumber").html();
        if (!workplanNumber || workplanNumber == "空") {
            return $alert("请先扫描机台号");
        }
        if ($("div.material span.number").html() && $("div.material span.number").html() != "空") {
            loading_show("获取中...");
            $.ajax({
                headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                type: "post",
                url: url + '/app/ropewire/getDataByMachine',
                dataType: 'json',
                data: {
                    id: work_id,
                    type: "收线",
                    machine: $("section span.machine").html()
                },
                json: 'callback',
                cache: false,
                timeout: 60000,
                success: function (res) {
                    if (res.success) {
                        var data = res.result;
                        loading_hide();
                        focus = false;
                        $(".mengceng").show();
                        $("div.div_shouxian").show();
                        $("div.div_shouxian input").val("");
                        $("div.div_shouxian input.length").val(data ? data.length : "").focus();
                        $("div.div_shouxian input.tareweight").val("0").trigger("change");
                        changeLength();
                        // $("div.div_shouxian input.actualDiameter").focus();
                        $("div.div_shouxian input.palletBatch").val(data ? data.palletBatch : "");
                        $("div.div_shouxian select").val("合格").trigger("change");
                    } else {
                        console.log(res);
                        $alert(res.message);
                    }
                },
                error: function (error) {
                    //隐藏提示符 显示
                    loading_hide();

                    if (error.status == 0) {
                        $alert("请求超时，请再试一次！");
                    } else {
                        console.log(error);
                        $alert(error.responseText);
                    }
                }
            });
        } else {
            $alert("请先上料！");
        }
    });
    //点击 收线 取消
    $("div.div_shouxian .sx_quxiao").click(function () {
        $(".mengceng").hide();
        $("div.div_shouxian").hide();
        $("#goods_id").focus();
        focus = true;
    });
    $("div.div_shouxian input.length").on("input", function () {
        changeLength();
    });
    function changeLength() {
        var zj = $("section span.work_gg").text().split(",")[0].replace(/m/ig, "");
        if ($("div.div_shouxian input.length").val()) {
            $("div.div_shouxian input.netweight").val(setWeight(zj, $("div.div_shouxian input.length").val()));
            $("div.div_shouxian input.grossweight").val(Number(parseFloat(accAdd($("div.div_shouxian input.netweight").val(), ($("div.div_shouxian input.tareweight").val() || 0))).toFixed(2)));
        } else {
            $("div.div_shouxian input.netweight").val();
        }
    }
    $("div.div_shouxian input.grossweight, div.div_shouxian input.tareweight, div.div_shouxian input.netweight").on("input", function () {
        $("div.div_shouxian input.grossweight").val(Number(parseFloat(accAdd($("div.div_shouxian input.netweight").val(), ($("div.div_shouxian input.tareweight").val() || 0))).toFixed(2)));
        $("div.div_shouxian input.netweight").val(Number(parseFloat(accSub($("div.div_shouxian input.grossweight").val(), ($("div.div_shouxian input.tareweight").val() || 0))).toFixed(2)));
    });

    //点击 收线 确定
    $(".sx_queding").click(function () {
        if (pass == 0) {
            return;
        }
        pass = 0;
        var zj = $("section span.work_gg").text().split(",")[0].replace(/m/ig, "");
        var zj_Min = Number(accSub(work.detail.inventoryDiameter, Math.abs(work.detail.diameterToleranceMin)));
        var zj_Max = Number(accAdd(work.detail.inventoryDiameter, Math.abs(work.detail.diameterToleranceMax)));
        var qualityInspectFrequency = work.detail.qualityInspectFrequency;
        console.log(zj_Max)
        console.log(zj_Min)
        console.log(qualityInspectFrequency)
        var grossweight = $("div.div_shouxian input.grossweight").val();
        var tareweight = $("div.div_shouxian input.tareweight").val();
        var netweight = $("div.div_shouxian input.netweight").val();

        /*if (!$("div.div_shouxian input.actualDiameter").val()) {
            pass = 1;
            $alert("实测直径不可为空");
            $("div.div_shouxian input.actualDiameter").focus();
        }
        else if ($("div.div_shouxian input.actualDiameter").val() < 0) {
            pass = 1;
            $alert("实测直径不可小于0");
            $("div.div_shouxian input.actualDiameter").focus();
        }
        else if (Math.abs(accSub($("div.div_shouxian input.actualDiameter").val(), zj)) > 1) {
            pass = 1;
            $alert("实测直径误差过大");
            $("div.div_shouxian input.actualDiameter").focus();
        }*/

        if (!$("div.div_shouxian input.length").val()) {
            pass = 1;
            $alert("机台米长不可为空");
            $("div.div_shouxian input.length").focus();
        }
        else if (Number($("div.div_shouxian input.length").val()) <= 0) {
            pass = 1;
            $alert("机台米长不可小于0");
            $("div.div_shouxian input.length").focus();
        }
        else if (Number(grossweight) < 0) {
            pass = 1;
            $alert("毛重不可小于0");
            $("div.div_shouxian input.grossweight").focus();
        }
        else if (Number(tareweight) < 0) {
            pass = 1;
            $alert("皮重不可小于0");
            $("div.div_shouxian input.tareweight").focus();
        }
        else if (Number(netweight) < 0) {
            pass = 1;
            $alert("净重不可小于0");
            $("div.div_shouxian input.netweight").focus();
        }
        else {
            /*if (Number($("div.div_shouxian input.actualDiameter").val()) > Number(zj_Max) || Number($("div.div_shouxian input.actualDiameter").val()) < Number(zj_Min)) {
                qualityJson.zj = "直径不合格";
            } else {
                qualityJson.zj = "";
            }*/
            if ($("div.div_shouxian .bmzl").val() == "不合格") {
                qualityJson.bmzl = "表面质量不合格";
            } else {
                qualityJson.bmzl = "";
            }
            var bhgx = [];
            for (var k in qualityJson) {
                if (qualityJson[k]) {
                    bhgx.push(qualityJson[k]);
                }
            }

            // var shouxianWeight = Number(setWeight(zj, $("div.div_shouxian input.length").val()));
            var shouxianWeight = Number(netweight);
            var work_weight = $("section span.work_weight").html();
            var work_completeWeight = accAdd(($("div.div_shouxian select.selfResult").val() == "合格" ? Number(shouxianWeight) : 0), $("section span.work_completeWeight").html());
            var chazhi = accSub(work_completeWeight, work_weight);
            var wheelQuantity = $("section span.work_zls").html();
            var completeWheelQuantity = $("section span.work_completeWheelQuantity").html();
            var lscz = accSub(wheelQuantity, completeWheelQuantity);
            console.log("轮数差值："+lscz)
            console.log(chazhi)
            console.log(controlvalue_E)
            if (qualityInspectFrequency == "全检") {
                //调用 收线 接口
                loading_show("收线中...");
                //拉丝 收线
                $.ajax({
                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                    type: "post",
                    url: url + '/app/ropewire/ropewireTakeup_end',
                    data: {
                        id: work_id,
                        machine: $("section span.machine").html(),
                        grossweight: grossweight,
                        tareweight: tareweight,
                        netweight: netweight,
                        palletBatch: $("div.div_shouxian input.palletBatch").val(),
                        weld: $("div.div_shouxian input.weld").val(),
                        length: $("div.div_shouxian input.length").val(),
                        actualDiameter: $("div.div_shouxian input.actualDiameter").val() || "",
                        bmzl: $("div.div_shouxian select.bmzl").val(),
                        selfResult: $("div.div_shouxian select.selfResult").val(),
                        wheelNumber: $("div.div_shouxian input.wheelNumber").val(),
                        bhgx: JSON.stringify(bhgx),
                        printAmount: 3
                    },
                    timeout: 30000,
                    dataType: 'json',
                    json: 'callback',
                    success: function (res) {
                        if (res.success) {
                            pass = 1;
                            //console.log(data);
                            //自动完工
                            // if (Number(chazhi) > Number(accMul(controlvalue_E, -1))) {
                            if (Number(lscz) <= 1) {
                                loading_hide();
                                $(".mengceng").hide();
                                $("div.div_shouxian").hide();
                                $.alert("已经达到计划轮数，确认完工吗？", function () {
                                    //收线完成，完工本机台计划
                                    loading_show("完工中...");
                                    $.ajax({
                                        headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                        type: "post",
                                        url: url + '/scheduleplan/ropewire/workover',
                                        data: {
                                            machine: $("section span.machine").html()
                                        },
                                        dataType: 'json',
                                        json: 'callback',
                                        success: function (result) {
                                            if (result.success) {
                                                loading_hide();
                                                $(".mengceng").hide();
                                                $("div.div_shouxian").hide();
                                                $.alert('当前计划已完工', function () {
                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                    // localStorage.removeItem("ropewireMachine");
                                                    window.location.href = "ropewire.html";
                                                });
                                            } else {
                                                loading_hide();
                                                $alert(res.message);
                                            }
                                        },
                                        error: function (error) {
                                            console.log(error);
                                            loading_hide();
                                            $alert(error.responseText);
                                        }
                                    });
                                }, function () {
                                    //收线完工，刷新本机台计划
                                    $.ajax({
                                        headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                        type: "post",
                                        url: url + '/scheduleplan/wire/takeup',
                                        data: {
                                            machine: $("section span.machine").html()
                                        },
                                        dataType: 'json',
                                        json: 'callback',
                                        success: function (res1) {
                                            if (res1.success) {
                                                loading_hide();
                                                $(".mengceng").hide();
                                                $("div.div_shouxian").hide();
                                                if (res1.isChange == "是") {
                                                    $alert("收线成功，计划已更新，请知悉");
                                                } else {
                                                    $alert("收线成功");
                                                }
                                                setTimeout(function () {
                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                    // localStorage.removeItem("ropewireMachine");
                                                    window.location.href = "ropewire.html";
                                                }, 1200);
                                            } else {
                                                loading_hide();
                                                $alert(res.message);
                                            }
                                        },
                                        error: function (error) {
                                            console.log(error);
                                            loading_hide();
                                            $alert(error.responseText);
                                        }
                                    });
                                })
                            }
                            //是否换规格
                            else if (Number(chazhi) > Number(accMul(controlvalue_D, -1))) {
                                //收线完工，刷新本机台计划
                                $.ajax({
                                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                    type: "post",
                                    url: url + '/scheduleplan/wire/takeup',
                                    data: {
                                        machine: $("section span.machine").html()
                                    },
                                    dataType: 'json',
                                    json: 'callback',
                                    success: function (res1) {
                                        if (res1.success) {
                                            loading_hide();
                                            $(".mengceng").hide();
                                            $("div.div_shouxian").hide();
                                            if (res1.nextInventoryMaterialSpecification) {
                                                //$alert("收线成功，计划已更新，请知悉");
                                                var html = '<span style="color: red; font-weight: bolder">请准备更换规格: ' + res1.nextInventoryMaterialSpecification + '</span>';
                                                $.alert(html, function () {
                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                    // localStorage.removeItem("ropewireMachine");
                                                    window.location.href = "ropewire.html";
                                                });
                                            } else {
                                                $alert("收线成功");
                                                setTimeout(function () {
                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                    // localStorage.removeItem("ropewireMachine");
                                                    window.location.href = "ropewire.html";
                                                }, 1200);
                                            }
                                        } else {
                                            console.log(res);
                                            loading_hide();
                                            $alert(res.message);
                                        }
                                    },
                                    error: function (error) {
                                        console.log(error);
                                        loading_hide();
                                        $alert(error.responseText);
                                    }
                                });
                            }
                            else {
                                //收线完工，刷新本机台计划
                                $.ajax({
                                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                    type: "post",
                                    url: url + '/scheduleplan/wire/takeup',
                                    data: {
                                        machine: $("section span.machine").html()
                                    },
                                    dataType: 'json',
                                    json: 'callback',
                                    success: function (res1) {
                                        if (res1.success) {
                                            loading_hide();
                                            $(".mengceng").hide();
                                            $("div.div_shouxian").hide();
                                            if (res1.isChange == "是") {
                                                $alert("收线成功，计划已更新，请知悉");
                                            } else {
                                                $alert("收线成功");
                                            }
                                            setTimeout(function () {
                                                localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                // localStorage.removeItem("ropewireMachine");
                                                window.location.href = "ropewire.html";
                                            }, 1200);
                                        } else {
                                            loading_hide();
                                            $alert(res.message);
                                        }
                                    },
                                    error: function (error) {
                                        console.log(error);
                                        loading_hide();
                                        $alert(error.responseText);
                                    }
                                });
                            }
                            // 打印 水箱 拉丝 收线 标签
                            if (!res.result.wheelNumber) {
                                takeupPrint("ropeWire", res.result);
                                takeupPrint("ropeWire", res.result);
                                takeupPrint("ropeWire", res.result);
                            } else {
                                takeupPrint("ropeWire", res.result);
                                takeupPrint("ropeWire", res.result);
                            }
                        } else {
                            pass = 1;
                            loading_hide();
                            $alert(res.message);
                        }
                    },
                    error: function (error) {
                        pass = 1;
                        if (error == 0) {
                            loading_hide();
                            $alert("请求超时，请重新操作！");
                        } else {
                            console.log(error);
                            loading_hide();
                            $alert(error.responseText);
                        }
                    }
                });
            } else if (qualityInspectFrequency == "免检") {
                //调用 收线 接口
                loading_show("收线中...");
                //拉丝 收线
                $.ajax({
                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                    type: "post",
                    url: url + '/app/ropewire/ropewireTakeup_end',
                    data: {
                        id: work_id,
                        machine: $("section span.machine").html(),
                        grossweight: grossweight,
                        tareweight: tareweight,
                        netweight: netweight,
                        palletBatch: $("div.div_shouxian input.palletBatch").val(),
                        weld: $("div.div_shouxian input.weld").val(),
                        length: $("div.div_shouxian input.length").val(),
                        actualDiameter: $("div.div_shouxian input.actualDiameter").val(),
                        bmzl: $("div.div_shouxian select.bmzl").val(),
                        selfResult: $("div.div_shouxian select.selfResult").val(),
                        wheelNumber: $("div.div_shouxian input.wheelNumber").val(),
                        bhgx: JSON.stringify(bhgx),
                        printAmount: 1
                    },
                    timeout: 30000,
                    dataType: 'json',
                    json: 'callback',
                    success: function (res) {
                        if (res.success) {
                            pass = 1;
                            //console.log(data);
                            //自动完工
                            // if (Number(chazhi) > Number(accMul(controlvalue_E, -1))) {
                            if (Number(lscz) <= 1) {
                                loading_hide();
                                $(".mengceng").hide();
                                $("div.div_shouxian").hide();
                                $.alert("已经达到计划轮数，确认完工吗？", function () {
                                    //收线完成，完工本机台计划
                                    loading_show("完工中...");
                                    $.ajax({
                                        headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                        type: "post",
                                        url: url + '/scheduleplan/ropewire/workover',
                                        data: {
                                            machine: $("section span.machine").html()
                                        },
                                        dataType: 'json',
                                        json: 'callback',
                                        success: function (result) {
                                            if (result.success) {
                                                loading_hide();
                                                $(".mengceng").hide();
                                                $("div.div_shouxian").hide();
                                                $.alert('当前计划已完工', function () {
                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                    // localStorage.removeItem("ropewireMachine");
                                                    window.location.href = "ropewire.html";
                                                });
                                            } else {
                                                loading_hide();
                                                $alert(res.message);
                                            }
                                        },
                                        error: function (error) {
                                            console.log(error);
                                            loading_hide();
                                            $alert(error.responseText);
                                        }
                                    });
                                }, function () {
                                    //收线完工，刷新本机台计划
                                    $.ajax({
                                        headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                        type: "post",
                                        url: url + '/scheduleplan/wire/takeup',
                                        data: {
                                            machine: $("section span.machine").html()
                                        },
                                        dataType: 'json',
                                        json: 'callback',
                                        success: function (res1) {
                                            if (res1.success) {
                                                loading_hide();
                                                $(".mengceng").hide();
                                                $("div.div_shouxian").hide();
                                                if (res1.isChange == "是") {
                                                    $alert("收线成功，计划已更新，请知悉");
                                                } else {
                                                    $alert("收线成功");
                                                }
                                                setTimeout(function () {
                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                    // localStorage.removeItem("ropewireMachine");
                                                    window.location.href = "ropewire.html";
                                                }, 1200);
                                            } else {
                                                loading_hide();
                                                $alert(res.message);
                                            }
                                        },
                                        error: function (error) {
                                            console.log(error);
                                            loading_hide();
                                            $alert(error.responseText);
                                        }
                                    });
                                });
                            }
                            //是否换规格
                            else if (Number(chazhi) > Number(accMul(controlvalue_D, -1))) {
                                //收线完工，刷新本机台计划
                                $.ajax({
                                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                    type: "post",
                                    url: url + '/scheduleplan/wire/takeup',
                                    data: {
                                        machine: $("section span.machine").html()
                                    },
                                    dataType: 'json',
                                    json: 'callback',
                                    success: function (res1) {
                                        if (res1.success) {
                                            loading_hide();
                                            $(".mengceng").hide();
                                            $("div.div_shouxian").hide();
                                            if (res1.nextInventoryMaterialSpecification) {
                                                //$alert("收线成功，计划已更新，请知悉");
                                                var html = '<span style="color: red; font-weight: bolder">请准备更换规格: ' + res1.nextInventoryMaterialSpecification + '</span>';
                                                $.alert(html, function () {
                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                    // localStorage.removeItem("ropewireMachine");
                                                    window.location.href = "ropewire.html";
                                                });
                                            } else {
                                                $alert("收线成功");
                                                setTimeout(function () {
                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                    // localStorage.removeItem("ropewireMachine");
                                                    window.location.href = "ropewire.html";
                                                }, 1200);
                                            }
                                        } else {
                                            console.log(res);
                                            loading_hide();
                                            $alert(res.message);
                                        }
                                    },
                                    error: function (error) {
                                        console.log(error);
                                        loading_hide();
                                        $alert(error.responseText);
                                    }
                                });
                            }
                            else {
                                //收线完工，刷新本机台计划
                                $.ajax({
                                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                    type: "post",
                                    url: url + '/scheduleplan/wire/takeup',
                                    data: {
                                        machine: $("section span.machine").html()
                                    },
                                    dataType: 'json',
                                    json: 'callback',
                                    success: function (res1) {
                                        if (res1.success) {
                                            loading_hide();
                                            $(".mengceng").hide();
                                            $("div.div_shouxian").hide();
                                            if (res1.isChange == "是") {
                                                $alert("收线成功，计划已更新，请知悉");
                                            } else {
                                                $alert("收线成功");
                                            }
                                            setTimeout(function () {
                                                localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                // localStorage.removeItem("ropewireMachine");
                                                window.location.href = "ropewire.html";
                                            }, 1200);
                                        } else {
                                            loading_hide();
                                            $alert(res.message);
                                        }
                                    },
                                    error: function (error) {
                                        console.log(error);
                                        loading_hide();
                                        $alert(error.responseText);
                                    }
                                });
                            }
                            // 打印 水箱 拉丝 收线 标签
                            if (!res.result.wheelNumber) {
                                takeupPrint("ropeWire", res.result);
                            }
                        } else {
                            pass = 1;
                            loading_hide();
                            $alert(res.message);
                        }
                    },
                    error: function (error) {
                        pass = 1;
                        if (error == 0) {
                            loading_hide();
                            $alert("请求超时，请重新操作！");
                        } else {
                            console.log(error);
                            loading_hide();
                            $alert(error.responseText);
                        }
                    }
                });
            } else {
                $.modal({
                    title:  '是否留样？',
                    buttons: [
                        {
                            text: '否',
                            onClick: function() {
                                //调用 收线 接口
                                loading_show("收线中...");
                                //拉丝 收线
                                $.ajax({
                                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                    type: "post",
                                    url: url + '/app/ropewire/ropewireTakeup_end',
                                    data: {
                                        id: work_id,
                                        machine: $("section span.machine").html(),
                                        grossweight: grossweight,
                                        tareweight: tareweight,
                                        netweight: netweight,
                                        palletBatch: $("div.div_shouxian input.palletBatch").val(),
                                        weld: $("div.div_shouxian input.weld").val(),
                                        length: $("div.div_shouxian input.length").val(),
                                        actualDiameter: $("div.div_shouxian input.actualDiameter").val(),
                                        bmzl: $("div.div_shouxian select.bmzl").val(),
                                        selfResult: $("div.div_shouxian select.selfResult").val(),
                                        wheelNumber: $("div.div_shouxian input.wheelNumber").val(),
                                        bhgx: JSON.stringify(bhgx),
                                        printAmount: 1
                                    },
                                    timeout: 30000,
                                    dataType: 'json',
                                    json: 'callback',
                                    success: function (res) {
                                        if (res.success) {
                                            pass = 1;
                                            //console.log(data);
                                            //自动完工
                                            // if (Number(chazhi) > Number(accMul(controlvalue_E, -1))) {
                                            if (Number(lscz) <= 1) {
                                                loading_hide();
                                                $(".mengceng").hide();
                                                $("div.div_shouxian").hide();
                                                $.alert("已经达到计划轮数，确认完工吗？", function () {
                                                    //收线完成，完工本机台计划
                                                    loading_show("完工中...");
                                                    $.ajax({
                                                        headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                                        type: "post",
                                                        url: url + '/scheduleplan/ropewire/workover',
                                                        data: {
                                                            machine: $("section span.machine").html()
                                                        },
                                                        dataType: 'json',
                                                        json: 'callback',
                                                        success: function (result) {
                                                            if (result.success) {
                                                                loading_hide();
                                                                $(".mengceng").hide();
                                                                $("div.div_shouxian").hide();
                                                                $.alert('当前计划已完工', function () {
                                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                                    // localStorage.removeItem("ropewireMachine");
                                                                    window.location.href = "ropewire.html";
                                                                });
                                                            } else {
                                                                loading_hide();
                                                                $alert(res.message);
                                                            }
                                                        },
                                                        error: function (error) {
                                                            console.log(error);
                                                            loading_hide();
                                                            $alert(error.responseText);
                                                        }
                                                    });
                                                }, function () {
                                                    //收线完工，刷新本机台计划
                                                    $.ajax({
                                                        headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                                        type: "post",
                                                        url: url + '/scheduleplan/wire/takeup',
                                                        data: {
                                                            machine: $("section span.machine").html()
                                                        },
                                                        dataType: 'json',
                                                        json: 'callback',
                                                        success: function (res1) {
                                                            if (res1.success) {
                                                                if (res1.isChange == "是") {
                                                                    $alert("收线成功，计划已更新，请知悉");
                                                                } else {
                                                                    $alert("收线成功");
                                                                }
                                                                setTimeout(function () {
                                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                                    // localStorage.removeItem("ropewireMachine");
                                                                    window.location.href = "ropewire.html";
                                                                }, 1200);
                                                            } else {
                                                                loading_hide();
                                                                $alert(res.message);
                                                            }
                                                        },
                                                        error: function (error) {
                                                            console.log(error);
                                                            loading_hide();
                                                            $alert(error.responseText);
                                                        }
                                                    });
                                                })
                                            }
                                            //是否换规格
                                            else if (Number(chazhi) > Number(accMul(controlvalue_D, -1))) {
                                                //收线完工，刷新本机台计划
                                                $.ajax({
                                                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                                    type: "post",
                                                    url: url + '/scheduleplan/wire/takeup',
                                                    data: {
                                                        machine: $("section span.machine").html()
                                                    },
                                                    dataType: 'json',
                                                    json: 'callback',
                                                    success: function (res1) {
                                                        if (res1.success) {
                                                            loading_hide();
                                                            $(".mengceng").hide();
                                                            $("div.div_shouxian").hide();
                                                            if (res1.nextInventoryMaterialSpecification) {
                                                                //$alert("收线成功，计划已更新，请知悉");
                                                                var html = '<span style="color: red; font-weight: bolder">请准备更换规格: ' + res1.nextInventoryMaterialSpecification + '</span>';
                                                                $.alert(html, function () {
                                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                                    // localStorage.removeItem("ropewireMachine");
                                                                    window.location.href = "ropewire.html";
                                                                });
                                                            } else {
                                                                $alert("收线成功");
                                                                setTimeout(function () {
                                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                                    // localStorage.removeItem("ropewireMachine");
                                                                    window.location.href = "ropewire.html";
                                                                }, 1200);
                                                            }
                                                        } else {
                                                            console.log(res);
                                                            loading_hide();
                                                            $alert(res.message);
                                                        }
                                                    },
                                                    error: function (error) {
                                                        console.log(error);
                                                        loading_hide();
                                                        $alert(error.responseText);
                                                    }
                                                });
                                            }
                                            else {
                                                //收线完工，刷新本机台计划
                                                $.ajax({
                                                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                                    type: "post",
                                                    url: url + '/scheduleplan/wire/takeup',
                                                    data: {
                                                        machine: $("section span.machine").html()
                                                    },
                                                    dataType: 'json',
                                                    json: 'callback',
                                                    success: function (res1) {
                                                        if (res1.success) {
                                                            loading_hide();
                                                            $(".mengceng").hide();
                                                            $("div.div_shouxian").hide();
                                                            if (res1.isChange == "是") {
                                                                $alert("收线成功，计划已更新，请知悉");
                                                            } else {
                                                                $alert("收线成功");
                                                            }
                                                            setTimeout(function () {
                                                                localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                                // localStorage.removeItem("ropewireMachine");
                                                                window.location.href = "ropewire.html";
                                                            }, 1200);
                                                        } else {
                                                            loading_hide();
                                                            $alert(res.message);
                                                        }
                                                    },
                                                    error: function (error) {
                                                        console.log(error);
                                                        loading_hide();
                                                        $alert(error.responseText);
                                                    }
                                                });
                                            }
                                            // 打印 水箱 拉丝 收线 标签
                                            if (!res.result.wheelNumber) {
                                                takeupPrint("ropeWire", res.result);
                                            }
                                        } else {
                                            pass = 1;
                                            loading_hide();
                                            $alert(res.message);
                                        }
                                    },
                                    error: function (error) {
                                        pass = 1;
                                        if (error == 0) {
                                            loading_hide();
                                            $alert("请求超时，请重新操作！");
                                        } else {
                                            console.log(error);
                                            loading_hide();
                                            $alert(error.responseText);
                                        }
                                    }
                                });
                            }
                        },{
                            text: '是',
                            onClick: function() {
                                //调用 收线 接口
                                loading_show("收线中...");
                                //拉丝 收线
                                $.ajax({
                                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                    type: "post",
                                    url: url + '/app/ropewire/ropewireTakeup_end',
                                    data: {
                                        id: work_id,
                                        machine: $("section span.machine").html(),
                                        grossweight: grossweight,
                                        tareweight: tareweight,
                                        netweight: netweight,
                                        palletBatch: $("div.div_shouxian input.palletBatch").val(),
                                        weld: $("div.div_shouxian input.weld").val(),
                                        length: $("div.div_shouxian input.length").val(),
                                        actualDiameter: $("div.div_shouxian input.actualDiameter").val(),
                                        bmzl: $("div.div_shouxian select.bmzl").val(),
                                        selfResult: $("div.div_shouxian select.selfResult").val(),
                                        wheelNumber: $("div.div_shouxian input.wheelNumber").val(),
                                        bhgx: JSON.stringify(bhgx),
                                        printAmount: 2
                                    },
                                    timeout: 30000,
                                    dataType: 'json',
                                    json: 'callback',
                                    success: function (res) {
                                        if (res.success) {
                                            pass = 1;
                                            //console.log(data);
                                            //自动完工
                                            // if (Number(chazhi) > Number(accMul(controlvalue_E, -1))) {
                                            if (Number(lscz) <= 1) {
                                                loading_hide();
                                                $(".mengceng").hide();
                                                $("div.div_shouxian").hide();
                                                $.alert("已经达到计划轮数，确认完工吗？", function () {
                                                    //收线完成，完工本机台计划
                                                    loading_show("完工中...");
                                                    $.ajax({
                                                        headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                                        type: "post",
                                                        url: url + '/scheduleplan/ropewire/workover',
                                                        data: {
                                                            machine: $("section span.machine").html()
                                                        },
                                                        dataType: 'json',
                                                        json: 'callback',
                                                        success: function (result) {
                                                            if (result.success) {
                                                                loading_hide();
                                                                $(".mengceng").hide();
                                                                $("div.div_shouxian").hide();
                                                                $.alert('当前计划已完工', function () {
                                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                                    // localStorage.removeItem("ropewireMachine");
                                                                    window.location.href = "ropewire.html";
                                                                });
                                                            } else {
                                                                loading_hide();
                                                                $alert(res.message);
                                                            }
                                                        },
                                                        error: function (error) {
                                                            console.log(error);
                                                            loading_hide();
                                                            $alert(error.responseText);
                                                        }
                                                    });
                                                }, function () {
                                                    //收线完工，刷新本机台计划
                                                    $.ajax({
                                                        headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                                        type: "post",
                                                        url: url + '/scheduleplan/wire/takeup',
                                                        data: {
                                                            machine: $("section span.machine").html()
                                                        },
                                                        dataType: 'json',
                                                        json: 'callback',
                                                        success: function (res1) {
                                                            if (res1.success) {
                                                                loading_hide();
                                                                $(".mengceng").hide();
                                                                $("div.div_shouxian").hide();
                                                                if (res1.isChange == "是") {
                                                                    $alert("收线成功，计划已更新，请知悉");
                                                                } else {
                                                                    $alert("收线成功");
                                                                }
                                                                setTimeout(function () {
                                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                                    // localStorage.removeItem("ropewireMachine");
                                                                    window.location.href = "ropewire.html";
                                                                }, 1200);
                                                            } else {
                                                                loading_hide();
                                                                $alert(res.message);
                                                            }
                                                        },
                                                        error: function (error) {
                                                            console.log(error);
                                                            loading_hide();
                                                            $alert(error.responseText);
                                                        }
                                                    });
                                                })
                                            }
                                            //是否换规格
                                            else if (Number(chazhi) > Number(accMul(controlvalue_D, -1))) {
                                                //收线完工，刷新本机台计划
                                                $.ajax({
                                                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                                    type: "post",
                                                    url: url + '/scheduleplan/wire/takeup',
                                                    data: {
                                                        machine: $("section span.machine").html()
                                                    },
                                                    dataType: 'json',
                                                    json: 'callback',
                                                    success: function (res1) {
                                                        if (res1.success) {
                                                            loading_hide();
                                                            $(".mengceng").hide();
                                                            $("div.div_shouxian").hide();
                                                            if (res1.nextInventoryMaterialSpecification) {
                                                                //$alert("收线成功，计划已更新，请知悉");
                                                                var html = '<span style="color: red; font-weight: bolder">请准备更换规格: ' + res1.nextInventoryMaterialSpecification + '</span>';
                                                                $.alert(html, function () {
                                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                                    // localStorage.removeItem("ropewireMachine");
                                                                    window.location.href = "ropewire.html";
                                                                });
                                                            } else {
                                                                $alert("收线成功");
                                                                setTimeout(function () {
                                                                    localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                                    // localStorage.removeItem("ropewireMachine");
                                                                    window.location.href = "ropewire.html";
                                                                }, 1200);
                                                            }
                                                        } else {
                                                            console.log(res);
                                                            loading_hide();
                                                            $alert(res.message);
                                                        }
                                                    },
                                                    error: function (error) {
                                                        console.log(error);
                                                        loading_hide();
                                                        $alert(error.responseText);
                                                    }
                                                });
                                            }
                                            else {
                                                //收线完工，刷新本机台计划
                                                $.ajax({
                                                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                                                    type: "post",
                                                    url: url + '/scheduleplan/wire/takeup',
                                                    data: {
                                                        machine: $("section span.machine").html()
                                                    },
                                                    dataType: 'json',
                                                    json: 'callback',
                                                    success: function (res1) {
                                                        if (res1.success) {
                                                            loading_hide();
                                                            $(".mengceng").hide();
                                                            $("div.div_shouxian").hide();
                                                            if (res1.isChange == "是") {
                                                                $alert("收线成功，计划已更新，请知悉");
                                                            } else {
                                                                $alert("收线成功");
                                                            }
                                                            setTimeout(function () {
                                                                localStorage.setItem("ropewireMachine", $("section span.machine").html());
                                                                // localStorage.removeItem("ropewireMachine");
                                                                window.location.href = "ropewire.html";
                                                            }, 1200);
                                                        } else {
                                                            loading_hide();
                                                            $alert(res.message);
                                                        }
                                                    },
                                                    error: function (error) {
                                                        console.log(error);
                                                        loading_hide();
                                                        $alert(error.responseText);
                                                    }
                                                });
                                            }
                                            // 打印 水箱 拉丝 收线 标签
                                            if (!res.result.wheelNumber) {
                                                takeupPrint("ropeWire", res.result);
                                                takeupPrint("ropeWire", res.result);
                                            } else {
                                                takeupPrint("ropeWire", res.result);
                                            }
                                        } else {
                                            pass = 1;
                                            loading_hide();
                                            $alert(res.message);
                                        }
                                    },
                                    error: function (error) {
                                        pass = 1;
                                        if (error == 0) {
                                            loading_hide();
                                            $alert("请求超时，请重新操作！");
                                        } else {
                                            console.log(error);
                                            loading_hide();
                                            $alert(error.responseText);
                                        }
                                    }
                                });
                            }
                        }
                    ]
                });
            }
        }
    });

    //点击 退料
    $(".bnt .returnMaterial").click(function () {
        var workplanNumber = $("section span.workplanNumber").html();
        if (!workplanNumber || workplanNumber == "空") {
            return $alert("请先扫描机台号");
        }
        if ($("div.material span.number").html() && $("div.material span.number").html() != "空") {
            focus = false;
            $(".mengceng").show();
            $("div.div_tuiliao").show();
            $("div.div_tuiliao input.syzl").val("").focus();
        } else {
            $alert("请先上料！");
        }
    });
    //点击 退料 取消
    $("div.div_tuiliao .tl_quxiao").click(function () {
        $(".mengceng").hide();
        $("div.div_tuiliao").hide();
        $("#goods_id").focus();
        focus = true;
    });
    //点击 退料 确定
    $("div.div_tuiliao .tl_queding").click(function () {
        if ($("div.div_tuiliao input.syzl").val() <= 0) {
            $alert("剩余重量应大于零");
            $("div.div_tuiliao input.syzl").focus();
        } else {
            //调用 收线 接口
            loading_show("退料中...");
            //拉丝 收线
            $.ajax({
                headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                type: "post",
                url: url + '/app/ropewire/ropewireReturnMaterial',
                data: {
                    id: work_id,
                    batch: $("section div.material span.number").html(),
                    machine: $("section span.machine").html(),
                    aweight: $("div.div_tuiliao input.syzl").val()
                },
                dataType: 'json',
                json: 'callback',
                success: function (res) {
                    if (res.success) {
                        loading_hide();
                        $alert("退料成功");
                        var machine = $("section span.machine").html();
                        localStorage.setItem("ropewireMachine", machine);
                        setTimeout(function () {
                            window.location.href = "ropewire.html";
                        }, 1200);
                    } else {
                        console.log(res);
                        loading_hide();
                        $alert(res.message);
                    }
                },
                error: function (error) {
                    console.log(error);
                    loading_hide();
                    $alert(error.responseText);
                }
            });
        }
    });

    //点击 换班
    $(".bnt .changeTeam").click(function () {
        var workplanNumber = $("section span.workplanNumber").html();
        if (!workplanNumber || workplanNumber == "空") {
            return $alert("请先扫描排产单");
        }
        if ($("div.material span.number").html() && $("div.material span.number").html() != "空") {
            loading_show("获取中...");
            $.ajax({
                headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                type: "post",
                url: url + '/app/ropewire/getDataByMachine',
                dataType: 'json',
                data: {
                    id: work_id,
                    type: "换班",
                    machine: $("section span.machine").html()
                },
                json: 'callback',
                cache: false,
                timeout: 60000,
                success: function (res) {
                    if (res.success) {
                        loading_hide();
                        focus = false;
                        var data = res.result;
                        $(".mengceng").show();
                        $("div.div_huanban").show();
                        $("div.div_huanban input.ywcmc").val(data.length).focus();
                    } else {
                        loading_hide();
                        $alert(res.message);
                    }
                },
                error: function (error) {
                    //隐藏提示符 显示
                    loading_hide();

                    if (error.status == 0) {
                        $alert("请求超时，请再试一次！");
                    } else {
                        console.log(error);
                        $alert(error.responseText);
                    }
                }
            });
        } else {
            $alert("请先上料！");
        }
    });
    //点击 换班 取消
    $("div.div_huanban .hb_quxiao").click(function () {
        $(".mengceng").hide();
        $("div.div_huanban").hide();
        $("#goods_id").focus();
        focus = true;
    });
    //点击 换班 确定
    $("div.div_huanban .hb_queding").click(function () {
        if ($("div.div_huanban input.ywcmc") <= 0) {
            $alert("已完成米长应大于零");
            $("div.div_huanban input.ywcmc").focus();
        } else {
            //调用 换班 接口
            loading_show("换班中...");
            //拉丝 收线
            $.ajax({
                headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                type: "post",
                url: url + '/app/ropewire/ropewireChangeTeam',
                data: {
                    id: work_id,
                    machine: $("section span.machine").html(),
                    length: $("div.div_huanban input.ywcmc").val()
                },
                dataType: 'json',
                json: 'callback',
                success: function (res) {
                    if (res.success) {
                        var data = res.result;
                        loading_hide();
                        $alert("换班成功");
                        setTimeout(function () {
                            localStorage.removeItem("ropewireMachine");
                            window.location.href = "ropewire.html";
                        }, 1200);
                    } else {
                        console.log(res);
                        loading_hide();
                        $alert(res.message);
                    }
                },
                error: function (error) {
                    console.log(error);
                    loading_hide();
                    $alert(error.responseText);
                }
            });
        }
    });

    //点击 查看计划
    $(".bnt .lookPlan").click(function () {
        var machine = $("section span.machine").html();
        var workplanNumber = $("section span.workplanNumber").html();
        if (!workplanNumber || workplanNumber == "空") {
            return $alert("请先扫描机台号");
        }
        if (!machine || machine == "空") {
            $alert("请先扫描拔丝机台");
        } else {
            localStorage.setItem("ropewireMachine", machine);
            window.location.href = "ropewire_ckjh.html";
        }
    });

    //点击 完工
    $(".bnt .workover").click(function () {
        var machine = $("section span.machine").html();
        var workplanNumber = $("section span.workplanNumber").html();
        if (!workplanNumber || workplanNumber == "空") {
            return $alert("请先扫描机台号");
        }
        if (!machine || machine == "空") {
            $alert("请先扫描拔丝机台");
        } else {
            var work_weight = $("section span.work_weight").html();
            var work_completeWeight = $("section span.work_completeWeight").html();
            if (Number(work_completeWeight) < Number(accSub(work_weight, 500))) return $alert("完成量小于计划量不可完工");
            $.confirm("确认完工吗？", function () {
                //调用 换班 接口
                loading_show("完工中...");
                //拉丝 机台 完工
                $.ajax({
                    headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                    type: "post",
                    url: url + '/scheduleplan/ropewire/workover',
                    data: {
                        machine: machine
                    },
                    dataType: 'json',
                    json: 'callback',
                    success: function (res) {
                        if (res.success) {
                            loading_hide();
                            $alert("完工成功");
                            localStorage.removeItem("ropewireMachine");
                            setTimeout(function () {
                                window.location.href = "ropewire.html";
                            }, 1200);
                        } else {
                            console.log(res);
                            loading_hide();
                            $alert(res.message);
                        }
                    },
                    error: function (error) {
                        console.log(error);
                        loading_hide();
                        $alert(error.responseText);
                    }
                });
            });
        }
    });

    //吊秤 扫描 获取 重量
    /*$("div.div_shouxian .scale").on("click", function (event) {
        var val = $("#goods_cheng").val();
        if (!val) {
            $alert("请选择吊秤编号！");
        } else {
            $.ajax({
                headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                type: "post",
                url: url + '/app/heat/getWeight',
                data: {
                    scale: val
                },
                dataType: 'json',
                json: 'callback',
                success: function (res) {
                    if (res.success) {
                        var data = res.result;
                        //$alert("重量获取成功", 800);
                        $("div.div_shouxian input.cpzl").val(data.weight).focus();
                    } else {
                        console.log(res);
                        $alert(res.message);
                    }
                },
                error: function (error) {
                    loading_hide();
                    console.log(error);
                    $alert(error.responseText);
                }
            });
        }
    });*/

});
